System.displayTreeNode = function(label,node) {
	function formatValue(vnode) {
		var value = '';
		
		if (vnode.type == Compiler.TOKEN_STRING) {
			value = vnode.value;
			value = '<b>"' + (value.length > 32 ? (value.substr(0,30) + '...') : 
				value) + '"</b> ';
		} else if (typeof vnode.value == 'string') {
			value = '<b>' + vnode.value + '</b> ';
		}
		return value;
	}
	var html = '<div class="tree-node"><div class="tree-wrap"><div class="tree-label"><span class="openbtn"></span><span class="closebtn"></span>' + label + '</div><div class="tree-block">', count = 0;
	for (var key in node) {
		html += '<div class="tree-element">';
		if (node[key] instanceof Array) {
			if (node[key].length > 0) {
				html += '<div class="tree-wrap"><div class="tree-label"><span class="openbtn"></span><span class="closebtn"></span>' + key + ':</div><div class="tree-block">';
				for (var i = 0; i < node[key].length; i++) {
					html += System.displayTreeNode('[' + i + '] ' + formatValue(node[key][i]) + (node[key][i].name ? '<b>' + node[key][i].name + '</b> ' : '') + (node[key][i].type ? '(' + System.REVERSE[node[key][i].type] + ')' : ''),node[key][i]);
				}
				html += '</div></div>';
				count++;
			}
		} else if (node[key] instanceof Object) {
			if (key != '^') {
				html += System.displayTreeNode(key + ': ' + (node[key].dataType ? '<b>' + node[key].dataType + '</b> ' : '') + formatValue(node[key]) + (node[key].type ? ('(' + System.REVERSE[node[key].type] + ')') : ''),node[key]);
				count++;
			}
		} else if (key != 'type' && key != 'name' && // key != 'lvalue' &&
				(key != 'value' || node[key] instanceof String)) {
			var value = node[key];
			if ({ access: true }[key]) value = System.REVERSE[node[key]];								
			html += '<div class="tree-leaf">' + key + ': ' + value + '</div>';
			count++;
		}
		html += '</div>';
	}
	if (count > 0) {
		return html + '</div></div></div>';
	} else {
		return '<div class="tree-node"><div class="tree-wrap"><div class="tree-label"><span class="btnspacer"></span>' + label + '</div><div class="tree-block"></div></div></div>';
	}
}

System.createReverseTable = function() {
	System.REVERSE = {};
	var key;
	for (key in Compiler) {
		if (key.match(/^TOKEN_/)) {
			System.REVERSE[Compiler[key]] = key.substring(6);
		}
	}
}

System.displayTree = function(tree) {
	if (!System.REVERSE) System.createReverseTable();
	var html = '';
	for (var i = 0; i < tree.length; i++) {
		html += System.displayTreeNode((tree[i].name ? ' <b>' + tree[i].name + '</b>' : '') + ' (' + System.REVERSE[tree[i].type] + ')',tree[i]);
	}
	return html;
}

System.reverseToken = function(token) {
	if (!System.REVERSE) System.createReverseTable();
	return 	System.REVERSE[token];
}

